﻿package com.toncen.samepms.portal.action;

import java.util.ArrayList;
import java.util.List;

import com.toncen.samepms.common.AbstractDatabaseAction;
import com.toncen.samepms.net.dao.ChannelDao;
import com.toncen.samepms.net.domain.Channel;

/**
 * 描述：栏目表NET_CHANNEL的action文件
 * 
 * @author xyp
 * @time 2013-5-10
 */
public class ChannelPublicAction extends AbstractDatabaseAction<Channel, ChannelDao> {
	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1365474907286L;

	public ChannelPublicAction() throws Exception {
		super();
	}

	/**
	 * 根栏目集合
	 */
	private List<Channel> rootChannels = new ArrayList<Channel>();

	/**
	 * 当前栏目默认展示下级栏目
	 */
	private List<Channel> defaultChannels = new ArrayList<Channel>();

	/**
	 * 是否高级检索
	 */
	private boolean advancedSearch = false;

	/**
	 * 获取根栏目
	 * 
	 * @return
	 * @throws Exception
	 */
	public String onDoHeaders() throws Exception {
		rootChannels = getDao().getAllRootChannel();
		return SUCCESS;
	}

	/**
	 * 获取下级栏目信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String onDoBrowers() throws Exception {
		prepareOnDoView();
		getDao().loadCascadeParent(getDomain());
		Channel channel;
		if (getDomainIds() != null) {
			for (long id : getDomainIds()) {
				channel = getDao().find(id);
				if (channel != null) {
					defaultChannels.add(channel);
				}
			}
		}else{
			defaultChannels.add(getDomain());
		}
		return SUCCESS;
	}

	/**
	 * 获取叶子栏目信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String onDoBrower() throws Exception {
		prepareOnDoView();
		getDao().loadCascadeParent(getDomain());
		return SUCCESS;
	}

	/**
	 * 检索
	 * 
	 * @return
	 * @throws Exception
	 */
	public String onDoSearch() throws Exception {
		if (getDomain().isSaved()) {// 指定栏目检索
			prepareOnDoView();
			getDao().loadCascadeParent(getDomain());
		} else {// 全站检索
			getDomain().getChilds().addAll(getDao().getAllRootChannel());
		}
		return SUCCESS;
	}

	public List<Channel> getRootChannels() {
		return rootChannels;
	}

	public void setRootChannels(List<Channel> channels) {
		this.rootChannels = channels;
	}

	public List<Channel> getDefaultChannels() {
		return defaultChannels;
	}

	public void setDefaultChannels(List<Channel> defaultChannels) {
		this.defaultChannels = defaultChannels;
	}

	public boolean isAdvancedSearch() {
		return advancedSearch;
	}

	public void setAdvancedSearch(boolean advancedSearch) {
		this.advancedSearch = advancedSearch;
	}

}
